/*

*/

#ifndef __HEADER_CLOCKSYNC
#define __HEADER_CLOCKSYNC
#include "../common/talk.h"
#include "listen.h"
#include <math.h>
#define PORT_LOG 5057
#define D_T 5 

void *appsendclk();
void *apprecvclk();
void *time_print(void *);
void *time_virtual();
void *app_clklog(void *);
void *app_listen(void *);
int musleep(unsigned long microsec);

extern void start_clocksync(int argc, char *argv[]);

extern clock_t t_virt, t_init, st_time;
extern long double tm_virt, tm_init, tm_clock;

extern pthread_mutex_t mutex3;

/*
Structure of the message that you want to send. Change here if need be.
Do not remove variables machine and dest_add for any application involving send and recv.
*/
typedef struct
{
  int type, machine;			//type defines the message type. Ensure that this is the first element.
  clock_t t0;
  long double tm0;
  unsigned long iteratn;
} msg_clksync;

//Message wrapped into mess_wrap with receive time after received by client.
typedef struct                                          //Do Not Change
{
  int type;
  msg_clksync m;
  clock_t t1;
  long double tm1;
} mess_wrap;

//Message wrapped into mess_s before sending by client with the send time.
typedef struct mess_s                                   //Do Not Change
{
  int type;
  mess_wrap msw;
  clock_t t2;
  long double tm2;
} msg_s;

typedef struct
{
  long double avg_time;
  long double avg_tm;
  int machine;
  unsigned long iteratn;
} t_print;

typedef struct
{
  int type, machine;			//type defines the message type. Ensure that this is the first element.
//  clock_t curr_time;
  long double strt_time;
  long double virt_time;
  unsigned long iteratn;
} msg_clklog;


#endif //__HEADER_CLOCKSYNC

